const DB = require('../tools/mysql')

module.exports = async ctx => {

  if (ctx.method === 'GET') {
    const [{ context }] = await DB('new').where('id', ctx.query.id).select('context')
    ctx.body = context || '无法打开此新闻，请稍后再试'
    return
  }

  const { type, commend } = ctx.request.body

  const param = { type }
  commend && (param.commend = commend)

  const data = await DB('new').where(param).select('id', 'name', 'url', 'time').orderBy('time', 'desc')

  ctx.body = { code: 1, msg: '查询成功', data }

}